package org.example.demo.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @ClassName: Fsk App
 * @Copyright: com.fsk
 * @Version: 1.0.0
 * @Author: chenming2
 * @UpdateTime: 2/27/2022
 * @Describe: XXXXXXX.
 */
@Aspect
@Component
@Order(0)
public class UserDaoProxy {
    @Pointcut("execution(* org.example.demo.dao.UserDao.add(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void before2() {
        System.out.println("公共切入点使用");
    }

    @Around("pointCut()")
    public void around2(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("Around。。。。。Before");
        proceedingJoinPoint.proceed();
        System.out.println("Around。。。。。After");
    }

    /**
     * 前置通知
     */
    @Before(value = "execution(* org.example.demo.dao.UserDao.add(..))")
    public void before() {
        System.out.println("调用代理前置通知");
    }

    /**
     * 最终通知
     */
    @After("execution(* org.example.demo.dao.UserDao.add(..))")
    public void after() {
        System.out.println("调用最终通知");
    }

    /**
     * 后置通知
     */
    @AfterReturning("execution(* org.example.demo.dao.UserDao.add(..))")
    public void afterReturning() {
        System.out.println("调用后置通知");
    }

    /**
     * 异常通知
     */
    @AfterThrowing("execution(* org.example.demo.dao.UserDao.add(..))")
    public void afterThrowing() {
        System.out.println("调用异常通知");
    }

    /**
     * 环绕通知
     * @param joinPoint
     * @throws Throwable
     */
    @Around("execution(* org.example.demo.dao.UserDao.add(..))")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕前...");
        // 被增强的方法执行
        joinPoint.proceed();
        System.out.println("环绕后...");
    }
}
